package com.hitrust.gs.action;


import com.hitrust.gs.bean.GSWarehouseStorageConfigBean;
import com.hitrust.gs.dao.GSWarehouseStorageConfigDAO;
import com.hitrust.gs.form.GSWarehouseStorageCofigForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;

public class GSWarehouseStorageConfigAction extends GSBaseAction {
	public String execute(GSBaseForm aForm) throws Exception {
		GSWarehouseStorageCofigForm gswcForm = (GSWarehouseStorageCofigForm)aForm;
		String codes = gswcForm.getWarehouseCode();
		
		String path = gswcForm.getRequest().getServletPath();
		String[] codeArr = codes.split(",");
		
		GSWarehouseStorageConfigDAO dao = new GSWarehouseStorageConfigDAO();
		
		if ("/A200001.do".equals(path)) {
			
			for (int i = 0; i < codeArr.length; i++) {
				GSWarehouseStorageConfigBean bean = dao.getWarehouseStorageConfig(codeArr[i]);
				if (bean != null) {
					dao.updateWarehouseStorageConfig(codeArr[i], "1");
				}else{
					dao.insertWarehouseStorageConfig(codeArr[i], "1"); //1表示启用
				}
			}
			
			gswcForm.getRequest().setAttribute("message", "启用库存设置成功！");
			
		}else{
			
			for (int i = 0; i < codeArr.length; i++) {
				GSWarehouseStorageConfigBean bean = dao.getWarehouseStorageConfig(codeArr[i]);
				if (bean != null) {
					dao.updateWarehouseStorageConfig(codeArr[i], "0");
				}else{
					dao.insertWarehouseStorageConfig(codeArr[i], "0"); //0表示不启用
				}
			}
			
			gswcForm.getRequest().setAttribute("message", "停用库存设置成功！");
		}
		
		return GSBaseConstants.FORWARD_SUCCESS;

	}
}
